<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="姓名" prop="name"
                :rules="[
                 ]">
              <el-input v-model="inputForm.name" placeholder="请填写姓名"     :disabled="true"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="学院" prop="institute"
                :rules="[
                 ]">
              <el-input v-model="inputForm.institute" placeholder="请填写学院"     :disabled="true"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="年级" prop="grade"
                :rules="[
                 ]">
              <el-input v-model="inputForm.grade" placeholder="请填写年级"     :disabled="true"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="班级" prop="classe"
                :rules="[
                 ]">
              <el-input v-model="inputForm.classe" placeholder="请填写班级"     :disabled="true"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="学号" prop="studentId"
                :rules="[
                 ]">
              <el-input v-model="inputForm.studentId" placeholder="请填写学号"     :disabled="true"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="学籍状态" prop="state"
                :rules="[
                 ]">
              <el-input v-model="inputForm.state" placeholder="请填写学籍状态"     :disabled="true"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否评价" prop="evaluate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.evaluate" placeholder="请填写是否评价"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="手写签名" prop="signature"
                :rules="[
                 ]">
              <el-input v-model="inputForm.signature" placeholder="请填写手写签名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="家长联系方式" prop="telphone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.telphone" placeholder="请填写家长联系方式"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="与学生关系" prop="relationship"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.relationship" placeholder="请填写与学生关系"     ></el-input> -->
                <el-select v-model="inputForm.relationship" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="家庭地址" prop="address"
                :rules="[
                 ]">
              <el-input v-model="inputForm.address" placeholder="请填写家庭地址" ></el-input>
           </el-form-item>
        </el-col>

        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          name: '',
          institute: '',
          classe: '',
          studentId: '',
          evaluate: '',
          signature: '',
          remarks: '',
          state: '',
          relationship: '',
          telphone: '',
          address: ''
        },
        options: [{
          value: '选项1',
          label: '父子'
        }, {
          value: '选项2',
          label: '母子'
        }, {
          value: '选项3',
          label: '祖孙'
        }, {
          value: '选项4',
          label: '叔侄'
        }, {
          value: '选项5',
          label: '姑侄'
        }, {
          value: '选项6',
          label: '舅甥'
        }],
        value: ''
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建学生评价`
        } else if (method === 'edit') {
          this.title = '修改学生评价'
        } else if (method === 'view') {
          this.title = '查看学生评价'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/studentevaluate/studentEvaluate/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.studentEvaluate)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/studentevaluate/studentEvaluate/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>
